package com.hebeu.gfh.service.impl;

import com.hebeu.gfh.mapper.ClubApplicationMapper;
import com.hebeu.gfh.mapper.ClubMemberMapper;
import com.hebeu.gfh.pojo.po.ClubApplication;
import com.hebeu.gfh.pojo.po.ClubMember;
import com.hebeu.gfh.pojo.vo.submitedApplication;
import com.hebeu.gfh.service.clubApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 刘剑利
 * @Version: v1.0
 */
@Service("clubApplicationService")
public class clubApplicationServiceImpl implements clubApplicationService {
    @Autowired
    ClubApplicationMapper clubApplicationMapper;
    @Autowired
    ClubMemberMapper clubMemberMapper;
    @Override
    public void submitApplication(ClubApplication clubApplication) {
        clubApplicationMapper.clubApplication(clubApplication);
    }

    @Override
    public List<submitedApplication> finfsubmitdApplication(int userId) {
        List<submitedApplication> submitedApplicationList;
        submitedApplicationList = clubApplicationMapper.finfsubmitdApplication(userId);
        return submitedApplicationList;
    }

    @Override
    public void passApplication(int applicationId) {
        clubApplicationMapper.passApplication(applicationId);
        ClubApplication application = clubApplicationMapper.findApplicationById(applicationId);
        ClubMember clubMember = new ClubMember();
        clubMember.setRoleInClub(1);
        clubMember.setClubId(application.getClubId());
        clubMember.setUserId(application.getUserId());
        clubMemberMapper.joinClub(clubMember);
    }

    @Override
    public void unpassApplication(int applicationId) {
        clubApplicationMapper.unpassApplication(applicationId);
    }

    @Override
    public ClubApplication getApplicationById(int applicationId) {
        ClubApplication application = clubApplicationMapper.findApplicationById(applicationId);
        return application;
    }


}
